package com.roamer.validator;


import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 自定义时间戳校验注解
 * <p>
 * {@link Constraint }定义自定义校验注解,{@code validatedBy}属性用于指定验证类
 * </p>
 *
 * @author roamer
 * @version V1.0
 * @date 2019/08/26 16:45
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(DateTime.List.class)
@Constraint(validatedBy = DateTimeValidator.class)
public @interface DateTime {

    String message() default "无效时间戳";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * 对比的时间维度
     *
     * @return {@code DimensionType}
     */
    DimensionType dimension() default DimensionType.day;

    /**
     * 时区偏移
     *
     * @return {@code String} 用于计算时区偏移 {@link java.util.TimeZone#getTimeZone(String)} (String)}
     */
    String timeZone() default "GMT+8:00";

    /**
     * 运算类型
     *
     * @return {@code MatchType}
     */
    MatchType matchType();

    /**
     * Bean的一个属性上可以添加多套规则
     */
    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        DateTime[] value();
    }

}
